#ifndef __HAL_I2C_H__
#define __HAL_I2C_H__

/*===========================================================================

Type definition.

===========================================================================*/

/* Type definition for I2C */
typedef enum
{
    I2C_CP_I2C,
    I2C_AUDIO_I2C,
    I2C_POWER_I2C,
} I2C_Type;

/* Speed definition for I2C */
typedef enum
{
    STANDARD_MODE = 0, /*100Kbps*/
    FAST_MODE = 1,     /*400Kbps*/
} I2C_MODE;

typedef enum
{
    I2C_RC_OK,
    I2C_RC_NOT_OK,
    I2C_RC_INVALID_DATA_SIZE,
    I2C_RC_INVALID_DATA_PTR,
    I2C_RC_TOO_MANY_REGISTERS,
    I2C_RC_TIMEOUT_ERROR,
    I2C_RC_CHIP_BUSY,
    I2C_RC_INVALID_GENERAL_CALL_SLAVE_ADDRESS,
    I2C_RC_UNREGISTER_ERR,
    I2C_RC_MESSAGE_QUEUE_IS_FULL,
    I2C_ISR_UNEXPECTED_INTERRUPT,
    I2C_ISR_BUS_ERROR,
    I2C_ISR_BUS_BUSY,
    I2C_ISR_EARLY_BUS_BUSY,
    I2C_ISR_CALL_BACK_FUNCTION_ERR,
    I2C_ISR_ARBITRATION_LOSS,
    I2C_RC_ILLEGAL_USE_OF_API
} I2C_ReturnCode;

/*****************************************************************
 * Function: hal_I2cInit
 *
 * Description:
 * 	Initial I2C bus
 *
 * Parameters:
 * 	i2c_type  	[in] 	 I2C Bus type
 *               			0: CP_I2C (SCL/SDA: GPIO_49/GPIO_50)
 *               			1: AUDIO_I2C (SCL/SDA: GPIO_10/GPIO_11)
 *               			2: POWER_I2C
 * 	i2c_mode	[in] 	 I2C mode
 * Return:
 * 	0:  success
 *	-1: error
 *
 *****************************************************************/
void hal_I2cInit(UINT8 i2c_type, UINT8 i2c_mode);

/*****************************************************************
 * Function: hal_I2cWrite
 *
 * Description:
 * 	Write Data to I2C
 *
 * Parameters:
 * 	i2c_type  		[in] 	I2C Bus type
 * 	slave_addr	    [in] 	I2C slave address
 * 	reg_addr		[in] 	I2C slave register
 * 	data	 		[in] 	the data
 * 	datalen	  		[in] 	data length
 * Return:
 * 	0:  success
 *	-1: error
 *
 *****************************************************************/
I2C_ReturnCode hal_I2cWrite(UINT8 i2c_type, UINT8 slave_addr, UINT8 reg_addr, UINT8 *data, UINT32 datalen);

/*****************************************************************
 * Function: hal_I2cRead
 *
 * Description:
 * 	Read data from I2C
 *
 * Parameters:
 * 	i2c_type  		[in] 	I2C Bus type
 * 	slave_addr	    [in] 	I2C slave address
 * 	reg_addr		[in] 	I2C slave register
 * 	data	 		[in] 	data buffer
 * 	datalen	  		[in] 	data length
 * Return:
 * 	0:  success
 *	-1: error
 *
 *****************************************************************/
I2C_ReturnCode hal_I2cRead(UINT8 i2c_type, UINT8 slave_addr, UINT8 reg_addr, UINT8 *data, UINT32 datalen);

#endif
